package com.future.hedongjun.mine.ui;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;

import com.future.baselib.activity.BaseActivity;
import com.future.baselib.entity.BaseResponse;
import com.future.baselib.entity.DefaultResponse;
import com.future.baselib.http.HttpRequest;
import com.future.hedongjun.common.MyApp;
import com.future.hedongjun.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class EditNicknameActivity extends BaseActivity {

    @BindView(R.id.et_nickname)
    EditText etNickname;
    @BindView(R.id.btn_ok)
    Button btnOk;
    private String nickname;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_nickname);
        ButterKnife.bind(this);
        setTitle("修改昵称");
        nickname = MyApp.getInstance().getUserInfo().getNickname();
    }

    @Override
    protected void getBundleExtras(Bundle extras) {
        super.getBundleExtras(extras);
    }

    @OnClick(R.id.btn_ok)
    public void onViewClicked() {
        String nickname = etNickname.getText().toString().trim();
        if (TextUtils.isEmpty(nickname)) {
            toast("昵称不能为空");
            return;
        }
        if (!TextUtils.isEmpty(this.nickname) && TextUtils.equals(nickname, this.nickname)) {
            toast("新昵称与旧昵称相同");
            return;
        }

        new HttpRequest<DefaultResponse>()
                .with(this)
                .setPath("/api/User/profile")
                .addParam("token", MyApp.getInstance().getUserInfo().getToken())
                .addParam("nickname", nickname)
                .addSuccessListener(new HttpRequest.OnNetworkSuccess() {
                    @Override
                    public void onSuccess(BaseResponse response) {
                        toast.show(response.msg);
                        setResult(RESULT_OK);
                        finish();
                    }
                }).start(new DefaultResponse());
//        new HttpRequest<>()
//                .with(this)
//                .setApiCode("_updateuserinfo_001")
//                .addParam("token", MyApp.getInstance().getUserInfo().getToken())
//                .addParam("nickname", nickname)
//                .addSuccessListener(new HttpRequest.OnNetworkSuccess() {
//                    @Override
//                    public void onSuccess(BaseResponse response) {

//                    }
//                }).start(new DefaultResponse());
    }
}
